package com.jhh.pay.center.cfg.tablesplit;

import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

/**
 * @author tangxd
 * @Description: TODO
 * @date 2017/12/5
 */
@Component("season_strategy")
public class SeasonStrategy implements Strategy {
    @Override
    public String getTable(Map<String, Object> params) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("YYYY");
        Date date = new Date();
        StringBuilder sb = new StringBuilder(params.get(Strategy.TABLE_NAME).toString());
        sb.append("_");
        sb.append(sdf.format(date));
        sb.append("_");
        sb.append(season());
        return sb.toString();
    }

    private int season() {
        Calendar calendar = Calendar.getInstance();
        int month = calendar.get(Calendar.MONTH);
        return (month + 1 + 4) / 4;
    }
}
